package com.happy.shiro.config.shiro;

import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheException;

import java.util.Collection;
import java.util.Set;

public class ShiroRedisCache implements Cache {

    private org.springframework.cache.Cache cache;

    ShiroRedisCache(org.springframework.cache.Cache cache) {
        this.cache = cache;
    }

    @Override
    public Object get(Object key) throws CacheException {
        org.springframework.cache.Cache.ValueWrapper valueWrapper = cache.get(key);
        if (valueWrapper != null) {
            return valueWrapper.get();
        }
        return null;
    }

    @Override
    public Object put(Object key, Object value) throws CacheException {
        cache.put(key, value);
        return value;
    }

    @Override
    public Object remove(Object key) throws CacheException {
        Object value = get(key);
        cache.evict(key);
        return value;
    }

    @Override
    public void clear() throws CacheException {
        cache.clear();
    }

    @Override
    public int size() {
        return 0;
    }

    @Override
    public Set keys() {
        return null;
    }

    @Override
    public Collection values() {
        return null;
    }
}
